import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/knowledgeword.dart';
import 'package:ichinesereader/models/knowledgeword/folderKnowledgeWordsDto.dart';
import 'package:ichinesereader/widgets/buttons/debouncedMaterialButton.dart';
import '../../themes/appTheme.dart';

// ignore: must_be_immutable
class DeleteWordDialog extends GetView<KnowledgeWordsController> {
  DeleteWordDialog({
    Key? key,
    required this.title,
    required this.message,
  }) : super(key: key);

  String title;
  String message;

  // KnowledgeWordsController controller = Get.find();

  void _deleteFolder() async {
    FolderKnowledgeWordsDto dto = controller.getSelectedFolderAWord();
    String? folderId = controller.currdir.length > 0
        ? controller.currdir[controller.currdir.length - 1]
        : '';
    if (((dto.folderIds?.length == 0) && (dto.knowledgeIds?.length == 0)) ||
        (folderId == '')) return;
    controller.removeKnowledgeWordsFromFolder(dto, folderId.toString());
  }

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(this.title),
          InkWell(
            onTap: () {
              Navigator.of(context).pop();
            },
            child: Icon(Icons.cancel,
                color: Get.isDarkMode ? Colors.white : Colors.blueGrey),
          ),
        ],
      ),
      titleTextStyle: TextStyle(
          letterSpacing: 1,
          color: Get.isDarkMode ? Get.theme.primaryColorDark : Colors.blueGrey,
          fontSize: 20),
      backgroundColor:
          Get.isDarkMode ? AppTheme.colors.darkTheme2 : Colors.white,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(
          Radius.circular(6.0),
        ),
      ),
      content: Container(
        height: 300.0,
        width: 450.0,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Flexible(
                  child: Padding(
                    padding: EdgeInsets.all(12.0),
                    child: Text.rich(
                        TextSpan(
                          text: this.message + ' ',
                          style: TextStyle(
                              color: Get.isDarkMode
                                  ? Get.theme.primaryColorDark
                                  : Colors.blueGrey),
                          children: <InlineSpan>[
                            TextSpan(
                              text: 'DELETE',
                              style: TextStyle(
                                  color: Get.isDarkMode
                                      ? Colors.white
                                      : AppTheme.colors.pinkBtn,
                                  fontSize: 18,
                                  decoration: TextDecoration.underline,
                                  decorationStyle: TextDecorationStyle.double),
                            ),
                            TextSpan(
                                text: '?',
                                style: TextStyle(
                                  color: Get.isDarkMode
                                      ? Colors.white
                                      : AppTheme.colors.pinkBtn,
                                ))
                          ],
                        ),
                        style: TextStyle(
                            color: Get.isDarkMode
                                ? Get.theme.primaryColorDark
                                : Get.theme.primaryColorLight)),
                  ),
                ),
              ],
            ),
            Center(
              child: Container(
                width: 210.0,
                height: 45.0,
                child: DebouncedMaterialButton(
                  color: Get.isDarkMode
                      ? (Colors.white)
                      : Theme.of(context).primaryColor,
                  textColor: Get.isDarkMode
                      ? (Colors.black)
                      : Theme.of(context).primaryColorLight,
                  onPressed: () {
                    _deleteFolder();
                    Navigator.of(context).pop();
                  },
                  child: Text(
                    'Submit'.tr,
                    style: TextStyle(
                        fontSize: 18.0,
                        color: Get.isDarkMode
                            ? Colors.black
                            : Get.theme.primaryColorLight),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
